package erp_services

import (
	"errors"
	"xiehui-service/app/models/erp_models"
	"xiehui-service/global"
)

const carSeqKey = "carSeq:"

type vehicleService struct {
}

var VehicleService = new(vehicleService)

// 查询有效的车辆
func (vehicleService *vehicleService) GetVehicles() (vehicles []erp_models.Vehicle, err error) {

	err = global.App.DB.Where("vehicle_status = ? ", 1).Find(&vehicles).Error

	if err != nil {
		if err.Error() == "record not found" {
			err = errors.New("数据不存在")
		}
	}
	return
}

// 查询车辆
func (vehicleService *vehicleService) GetVehicle(vehicle_id int) (vehicle erp_models.Vehicle, err error) {

	err = global.App.DB.First(&vehicle, vehicle_id).Error

	if err != nil {
		if err.Error() == "record not found" {
			err = errors.New("数据不存在")
		}
	}
	return
}
